import request from '@/utils/request'
import type {
  UserResponseData,
  User,
  AllRoleResponseData,
  SetRoleData,
  SearchUser,
  UserListResponseData,
} from './type'

//项目用户相关的地址
enum API {
  ALLUSER_URL = '/sysUser/getAllUsers',
  ALLUSERLIST_URL = '/sysUser/getAllUsersList',
  ADDUSER_URL = '/admin/acl/user/save',
  UPDATEUSER_URL = '/admin/acl/user/update',
  ALLROLEURL = '/sysRole/all',
  SETROLE_url = '/sysRole/addUserRole',
  DELETEUSER_URL = '/admin/acl/user/remove/',
  DELETEALLUSER_URL = '/admin/acl/user/batchRemove',
}

export const reqUserInfo = (params: SearchUser) =>
  request.get<any, UserResponseData>(API.ALLUSER_URL, { params: params })
export const reqUserInfoList = () =>
  request.get<any, UserListResponseData>(API.ALLUSERLIST_URL)

export const reqAddOrUpdateUser = (data: User) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATEUSER_URL, data)
  } else {
    return request.post<any, any>(API.ADDUSER_URL, data)
  }
}

export const reqAllRole = () =>
  request.get<any, AllRoleResponseData>(API.ALLROLEURL)

export const reqSetUserRole = (data: SetRoleData) =>
  request.put<any, any>(API.SETROLE_url, data)

export const reqRemoveUser = (userId: number) =>
  request.delete<any, any>(API.DELETEUSER_URL + userId)

export const reqSelectUser = (idList: number[]) =>
  request.delete(API.DELETEALLUSER_URL, { data: idList })
